﻿using DevExpress.XtraEditors.Repository;
using DevExpress.XtraTreeList.Columns;
using HuaWei;
using HuaWei.CommClass;
using HuaWei.DAI;
using System;
using System.Data;
using System.Runtime.InteropServices;

internal static class Class39
{
    public static void lquywmUul(TreeListColumn treeListColumn)
    {
        DataTable table = new DataTable();
        table.Columns.Add("code", typeof(int));
        table.Columns.Add("value", typeof(string));
        DataRow row = table.NewRow();
        row["code"] = 0;
        row["value"] = "业主";
        table.Rows.Add(row);
        row = table.NewRow();
        row["code"] = 1;
        row["value"] = "监理";
        table.Rows.Add(row);
        row = table.NewRow();
        row["code"] = 2;
        row["value"] = "标段";
        table.Rows.Add(row);
        RepositoryItemLookUpEdit columnEdit = (RepositoryItemLookUpEdit)treeListColumn.ColumnEdit;
        columnEdit.DataSource = table;
        columnEdit.DisplayMember = "value";
        columnEdit.ValueMember = "code";
    }

    public static void SetDYYFK(IDataAccess idataAccess, DataRow dataRow, string _str, string _str1)
    {
        Log.Write("SetDYYFK Begin");
        string sql = null;

        sql = string.Format("select KDYYFKGS from ZZJGXXEX  where id='{0}'", _str);
        BZGSKH bzgskh = new BZGSKH(DBHelp.GetDt(idataAccess, sql, "t_zzjg").Rows[0]["KDYYFKGS"].ToString());
        sql = string.Format("select sum(htje) as htje from jlqd where ZBCD=0 and CJM=0 and bdid='{0}'", _str);
        DataTable table2 = DBHelp.GetDt(idataAccess, sql, "dtTemp");
        decimal num7 = 0M; //合同总价
        decimal num9 = 0M; //暂列金
        if (table2.Rows.Count > 0)
        {
            num7 = CHelp.ConvertDecimal(CHelp.ConvertDecimal(table2.Rows[0][0], 0, 0), 0, 0);
        }

        sql = string.Format("select sum(htje) as htje from (select case when sgtyx=1 then sgtje else htje end as htje from jlqd where ZBCD=0 and CJM<>0 AND BDID='{0}')a", _str);
        DataTable table22 = DBHelp.GetDt(idataAccess, sql, "dtTemp");
        if (table22.Rows.Count > 0)
        {
            decimal num8 = CHelp.ConvertDecimal(CHelp.ConvertDecimal(table22.Rows[0][0], 0, 0), 0, 0);
            if (num8 < num7)
            {
                num7 = num8;
            }
        }

        bzgskh.HTZJ = num7;
        sql = string.Format("select htje from jlqd where qdbh in ('Z','z') and bdid='{0}'", _str);
        table2 = DBHelp.GetDt(idataAccess, sql, "ZDJE");
        if (table2.Rows.Count > 0)
        {
            num9 = CHelp.ConvertDecimal(CHelp.ConvertDecimal(table2.Rows[0][0], 0, 0), 0, 0);
            num7 = num7 - num9;
        }

        decimal num = 0M; //上期末完成
        decimal num2 = 0M;//上期末支付动员预付款
        decimal num3 = 0M;//上期末扣除动员预付款
        decimal num6 = 0M;//进度总额
        sql = "\r\nselect sum(a.bqjls*b.zbdj) as dj from (\r\nselect qdbh,bqjls from qdjl_mx where bdid='{0}' and qcid<={1}\r\nunion all\r\nselect qdbh,bqjls from bgqdjl_mx where bdid='{0}' and qcid<={1}\r\n) as a left join jlqd as b on a.qdbh=b.qdbh where b.bdid='{0}'\r\n";
        sql = string.Format(sql, _str, _str1);
        DataTable table3 = DBHelp.GetDt(idataAccess, sql, "dtQDJL");
        if (table3.Rows.Count > 0)
        {
            num6 = CHelp.ConvertDecimal(table3.Rows[0][0], 0, 0);
        }
        if (Convert.ToInt16(_str1) > 1)
        {
            sql = string.Format("select * from QTJL_DYYFK  where bdid='{0}' and qcid={1}-1", _str, _str1);
            DataTable table5 = DBHelp.GetDt(idataAccess, sql, "SQDYYFK");
            if (table5.Rows.Count > 0)
            {
                DataRow row = table5.Rows[0];
                num = CHelp.ConvertDecimal(row["BQMWC"], 0, 0);
                num2 = CHelp.ConvertDecimal(row["BQMZFDYYFK"], 0, 0);
                num3 = CHelp.ConvertDecimal(row["BQMKCDYYFK"], 0, 0);
            }
            else
            {
                num = 0M;
                num2 = 0M;
                num3 = 0M;
            }
        }
        bzgskh.QKE = CHelp.ConvertDecimal((bzgskh.HTZJ * bzgskh.QKEBL) / 100M, 0, 0);
        decimal num10 = CHelp.ConvertDecimal(dataRow["BQSQDYYFK"], 0, 0);
        dataRow["YFDYYFK"] = num2;
        dataRow["BQMZFDYYFK"] = num10 + num2;
        dataRow["HTZJ"] = bzgskh.HTZJ;
        dataRow["DYYFKZE"] = bzgskh.DYYFKZE;
        dataRow["QKE"] = bzgskh.QKE;
        decimal num4 = 0; //本期扣除动员预付款
        if (_str.ToUpper().Equals("3C52CE84-E6CE-4B1A-A084-BDBD9A9A5DBB") || _str.ToUpper().Equals("C7D7F25C-9924-45BD-8737-E3DF8CC042E9"))
        {
            if (_str1 == "2")
            {
                num4 = 3000000;
            }
            //峨祁施工三标
            else if (_str.ToUpper().Equals("C7D7F25C-9924-45BD-8737-E3DF8CC042E9") && _str1 == "4")
            {
                num4 = 5400000;
            }
            else
            {
                num4 = CalculateBQKCDYYFK(num6, bzgskh.QKE, bzgskh.DYYFKZE, bzgskh.HTZJ, num);
            }
        }
        //峨祁施工二标
        else if (_str.ToUpper().Equals("04D18B50-4C49-4B9A-AEF8-190BC6820537"))
        {
            if (_str1 == "3")
            {
                num4 = 3000000;
            }
            else if (_str1 == "4")
            {
                num4 = 0;
            }
            else if (_str1 == "5")
            {
                num4 = 6400000;
            }
            else
            {
                num4 = CalculateBQKCDYYFK(num6, bzgskh.QKE, bzgskh.DYYFKZE, bzgskh.HTZJ, num);
            }
        }
        //民小施工六标
        else if (_str.ToUpper().Equals("379EE239-49D6-41F1-B330-5FCB2110C77A"))
        {
            if (_str1 == "7")
            {
                num4 = 313068;
            }
            else
            {
                num4 = CalculateBQKCDYYFK(num6, bzgskh.QKE, bzgskh.DYYFKZE, bzgskh.HTZJ, num);
            }
        }
        //民小施工七标
        else if (_str.ToUpper().Equals("5C9CAF46-36FB-4235-AD3E-B41E7F48E4A1"))
        {
            if (_str1 == "6")
            {
                num4 = 0;
            }
            else
            {
                num4 = CalculateBQKCDYYFK(num6, bzgskh.QKE, bzgskh.DYYFKZE, bzgskh.HTZJ, num);
            }
        }
        //大地湾A标
        else if (_str.ToUpper().Equals("FE46FA50-9F98-4EB4-AE1B-435F7A95A325"))
        {
            if (_str1 == "2" || _str1 == "6")
            {
                num4 = 791585;
            }
            else if (_str1 == "1" || _str1 == "3" || _str1 == "4" || _str1 == "5" || _str1 == "7")
            {
                num4 = 0;
            }
            else
            {
                num4 = CalculateBQKCDYYFK(num6, bzgskh.QKE, bzgskh.DYYFKZE, bzgskh.HTZJ, num);
            }
        }
        else
        {
            num4 = CalculateBQKCDYYFK(num6, bzgskh.QKE, bzgskh.DYYFKZE, bzgskh.HTZJ, num);
        }
        if (num4 != 0)
        {
            num4 = CHelp.ConvertDecimal(num4, 0, 0);
        }
        dataRow["BQKCDYYFK"] = num4;
        dataRow["SQMWC"] = num;
        dataRow["BQMWC"] = num + num4;
        dataRow["BQWC"] = num6;
        dataRow.EndEdit();
        Log.Write("SetDYYFK End");
    }

    /// <summary>
    /// 计算本期扣除动员预付款
    /// </summary>
    /// <param name="jlze">计量总额</param>
    /// <param name="qke">起扣额</param>
    /// <param name="dyffkze">动员预付款总额</param>
    /// <param name="htzj">合同总额</param>
    /// <param name="sqmkcdyfyk">上期末扣除动员预付款</param>
    /// <returns></returns>
    private static decimal CalculateBQKCDYYFK(decimal jlze, decimal qke, decimal dyffkze, decimal htzj, decimal sqmkcdyfyk)
    {
        decimal bqkcdyyfk = 0;
        if (jlze > qke && htzj != 0)
        {
            decimal bqmkcdyyfk = (dyffkze * (jlze - qke) * 2) / htzj;
            if (bqmkcdyyfk > dyffkze)
            {
                bqkcdyyfk = dyffkze - sqmkcdyfyk;
            }
            else
            {
                if (bqmkcdyyfk <= sqmkcdyfyk)
                {
                    bqkcdyyfk = 0;
                }
                else
                {
                    bqkcdyyfk = bqmkcdyyfk - sqmkcdyfyk;
                }
            }
        }
        return bqkcdyyfk;
    }

    public static void smethod1(IDataAccess idataAccess, DataRow dataRow, string _str, string _str1)
    {
        string sql = "";
        int num = CHelp.ConvertInt(_str, 0);
        sql = string.Format("select * from ZZJGXXEX where id='{0}'", _str1);
        GQKK gqkk = new GQKK(DBHelp.GetDt(idataAccess, sql, "ZZJGXXEX").Rows[0]["KCLYYKGS"].ToString());
        new DataSet();
        int gQ = gqkk.GQ;
        int kHJDQ = gqkk.KHJDQ;
        decimal num4 = 0M;
        decimal num5 = 0M;
        decimal num6 = 0M;
        decimal num7 = 0M;
        decimal num8 = 0M;
        decimal num9 = DHelp.ToDecimal(dataRow["BQDFJE"]);
        DataTable dt = DBHelp.GetDt(string.Format("select * from QTJL_CLYFK where bdid='{0}' and qcid={1}-1", _str1, num), "QTJL_CLYFK");
        if (dt.Rows.Count > 0)
        {
            num7 = CHelp.ConvertDecimal(dt.Rows[0]["LJDFJE"], 0, 0);
        }
        if ((num > 1) && ((num - gQ) > 0))
        {
            sql = string.Format("select * from QTJL_CLYFK  where bdid='{0}' and qcid>{1} and qcid<={2}", _str1, (num - kHJDQ) - gQ, num - kHJDQ);
            DataTable table3 = DBHelp.GetDt(idataAccess, sql, "QTJL_CLYFK");
            int num10 = 0;
            int num11 = 0;
            foreach (DataRow row in table3.Rows)
            {
                num10 = Convert.ToInt16(row["qcid"]);
                num11 = Convert.ToInt16((int)(Convert.ToInt16(row["BQDFJE"]) / kHJDQ));
                if (((num10 - gQ) - kHJDQ) == 0)
                {
                    num4 += Convert.ToInt16(row["BQDFJE"]) - (num11 * (kHJDQ - 1));
                }
                else
                {
                    num4 += num11;
                }
            }
            sql = string.Format("select * from QTJL_CLYFK where bdid='{0}' and qcid='{1}'", _str1, num - 1);
            DataTable table4 = DBHelp.GetDt(idataAccess, sql, "QTJL_CLYFK");
            if (table4.Rows.Count > 0)
            {
                num5 = DHelp.ToDecimal(table4.Rows[0]["BQMKHJE"]);
                num7 = DHelp.ToDecimal(table4.Rows[0]["LJDFJE"]);
            }
            else
            {
                num5 = 0M;
                num7 = 0M;
            }
        }
        num6 = num4 + num5;
        num8 = num9 + num7;
        dataRow["BQKHJE"] = num4;
        dataRow["SQMKHJE"] = num5;
        dataRow["BQMKHJE"] = num6;
        dataRow["SQMDFJE"] = num7;
        dataRow["BQDFJE"] = num9;
        dataRow["LJDFJE"] = num8;
        dataRow.EndEdit();
    }

    public static void smethod10(IDataAccess idataAccess, DataSet dataSet, string _str, string _str1)
    {
        string exeStr = string.Format("delete from REFBGL where bdid='{0}' and qcid={1}", _str1, _str);
        idataAccess.ExecuteNonQuery(exeStr, CommandType.Text);
        exeStr = string.Format("insert into REFBGL(id,bdid,qcid,bglid) select id,bdid,{0},id from bgl where bdid='{1}' and tysb=1", _str, _str1);
        idataAccess.ExecuteNonQuery(exeStr, CommandType.Text);
    }

    public static void smethod11(IDataAccess idataAccess, string _str, string _str1)
    {
        string sql = CHelp.smethod(string.Format(CRepSQL.INSERT_ZQZFZS_XJ, _str1, _str));
        DBHelp.ExeSql(idataAccess, sql);
        sql = CHelp.smethod(string.Format(CRepSQL.INSERT_ZQZFZS_HJ, _str1, _str));
        DBHelp.ExeSql(idataAccess, sql);
        sql = CHelp.smethod(string.Format(CRepSQL.INSERT_ZQZFZS_ZF, _str1, _str));
        DBHelp.ExeSql(idataAccess, sql);
    }

    public static void smethod12(string _str)
    {
        IDataAccess ida = DBHelp.IniIDA();
        string sql = string.Format("select * from xmqc where bdid='{0}'", _str);
        DataTable table = DBHelp.GetDt(ida, sql, "dtTemp");
        string str2 = "";
        string str3 = "";
        foreach (DataRow row in table.Rows)
        {
            if (!row["zt"].Equals(1))
            {
                str2 = row["xmid"].ToString();
                str3 = row["yzid"].ToString();
                smethod15(_str, row["qcid"].ToString(), str2, str3, false, true);
            }
        }
    }

    //扣保留金
    public static void smethod13(IDataAccess idataAccess, string _str, string _str1, decimal _decimal)
    {
        decimal num = 0M;
        decimal o = 0M;

        string format = "select KBLJ from REP_ZQJKZF2 where bdid='{0}' and jllx=1 and qcid={1}-1";
        format = string.Format(format, _str1, _str);
        DataTable table = DBHelp.GetDt(idataAccess, format, "t_kblj");
        if (table.Rows.Count > 0)
        {
            num = CHelp.ConvertDecimal(table.Rows[0]["KBLJ"], 0, 0);
        }
        format = string.Format("select KHBLJGS from ZZJGXXEX  where id='{0}'", _str1);
        KHBLJ_BZGSKH khblj_bzgskh = new KHBLJ_BZGSKH(DBHelp.GetDt(idataAccess, format, "t_blj").Rows[0]["KHBLJGS"].ToString());

        decimal ZE = 0M;
        format = @"SELECT ROUND((CASE WHEN SUM(HTJE) >SUM(BGHJE) THEN SUM(HTJE) ELSE SUM(BGHJE) END)*0.05,0)  AS ZE FROM (
                SELECT A.QDBH,A.HTJE,(case when a.sgtyx=1 then a.sgtje else a.htje end)+ (case when b.BGZJJE is null  then 0 else b.BGZJJE end) as bghje FROM 
                (select QDBH,htje,sgtyx,sgtje FROM JLQD where bdid='{0}' AND pid!='-1' AND ((HTJE is not null and HTJE<>0) or (sgtje is not null and sgtje<>0))) A
                LEFT JOIN 
                (SELECT QDBH,SUM(BGZJJE) AS BGZJJE FROM BGLQD where bdid='{0}' GROUP BY QDBH) AS B
                ON A.QDBH=B.QDBH
                UNION ALL
                SELECT QDBH,0 AS htje1,SUM(BGZJJE) AS bghje FROM BGLQD 
                where bdid='{0}' AND QDBH NOT IN (SELECT QDBH FROM JLQD where bdid='{0}') 
                GROUP BY QDBH) C";
        format = string.Format(format, _str1);
        DataTable tableZE = DBHelp.GetDt(idataAccess, format, "ZE");
        if (table.Rows.Count > 0)
        {
            ZE = CHelp.ConvertDecimal(table.Rows[0]["ZE"], 0, 0);
        }

        if (!ZE.Equals((decimal)0M) && ((_decimal > khblj_bzgskh.QKJE) && (ZE > num)))
        {
            //8标
            if (_str1.ToUpper().Equals("14078319-A76F-4418-88A7-4A6FF7E7AA0B") && _str == "1")
            {
                o = (_decimal * 1) / 100M;
            }
            //民和主干道A
            else if (_str1.ToLower().Equals("263f75d3-6f7e-4dbb-8519-9ab586869600") && _str == "1")
            {
                o = (_decimal * 5) / 100M;
            }
            //峨祁施工二标
            else if (_str1.ToUpper().Equals("04D18B50-4C49-4B9A-AEF8-190BC6820537"))
            {
                if (_str == "3")
                {
                    o = 1802568;
                }
                else if (_str == "5")
                {
                    o = 3553569;
                }
                else
                {
                    o = (_decimal * khblj_bzgskh.KHBL) / 100M;
                }
            }
            //峨祁施工三标
            else if (_str1.ToUpper().Equals("C7D7F25C-9924-45BD-8737-E3DF8CC042E9") && _str == "4")
            {
                o = 3536049;
            }
            //民小施工五标
            else if (_str1.ToUpper().Equals("EDCCCD81-9C6C-45C3-9A3A-B2E388DF94C3") && _str == "8")
            {
                o = (_decimal * khblj_bzgskh.KHBL) / 100M-1;
            }
            //民小施工6标
            else if (_str1.ToLower().Equals("379ee239-49d6-41f1-b330-5fcb2110c77a") && _str == "18")
            {
                o = 18000000;
            }
            //民小施工8标
            else if (_str1.ToUpper().Equals("14078319-A76F-4418-88A7-4A6FF7E7AA0B") && _str == "20")
            {
                o = 11000000;
            }
            else
            {
                o = (_decimal * khblj_bzgskh.KHBL) / 100M;
            }
            if (o > (khblj_bzgskh.BLJZE - num) && !(_str1.ToUpper().Equals("04D18B50-4C49-4B9A-AEF8-190BC6820537") && _str != "5") && !(_str1.ToUpper().Equals("C7D7F25C-9924-45BD-8737-E3DF8CC042E9") && _str == "4"))
            {
                o = khblj_bzgskh.BLJZE - num;
            }
        }
        o = CHelp.ConvertDecimal(o, 0, 0);
        format = string.Format(CRepZFJKSQL.REP21_1, _str1, _str, o);
        DBHelp.ExeSql(idataAccess, format);
    }

    //更新支表一数据 
    public static void smethod14(IDataAccess idataAccess, string _str, string _str1)
    {
        string sql = string.Format(CRepZFJKSQL.REP00, _str1, _str);
        DBHelp.ExeSql(idataAccess, sql);
        sql = string.Format(CRepZFJKSQL.REP10, _str1, _str);
        DBHelp.ExeSql(idataAccess, sql);
        sql = string.Format(CRepZFJKSQL.REP11, _str1, _str);
        DBHelp.ExeSql(idataAccess, sql);
        sql = string.Format(CRepZFJKSQL.REP12, _str1, _str);
        DBHelp.ExeSql(idataAccess, sql);
        sql = string.Format(CRepZFJKSQL.REP13, _str1, _str);
        DBHelp.ExeSql(idataAccess, sql);
        sql = string.Format(CRepZFJKSQL.REP14, _str1, _str);
        DBHelp.ExeSql(idataAccess, sql);
        sql = string.Format(CRepZFJKSQL.REP15, _str1, _str);
        DBHelp.ExeSql(idataAccess, sql);
        sql = string.Format(CRepZFJKSQL.REP20, _str1, _str);
        DBHelp.ExeSql(idataAccess, sql);
        sql = string.Format(CRepZFJKSQL.SEARCH19, _str1, _str);
        string str2 = DBHelp.GetDt(idataAccess, sql, "ZQJKZF_HJ").Rows[0]["hj"].ToString();

        sql = string.Format("select * from xmqc where bdid='{0}' and qcid='{1}'", _str1, _str);
        DataTable table = DBHelp.GetDt(idataAccess, sql, "dtTemp");
        if (table != null && table.Rows.Count == 1 && table.Rows[0]["JSRQ"] != System.DBNull.Value && Convert.ToDateTime(table.Rows[0]["JSRQ"]).CompareTo(Convert.ToDateTime("2016-05-01")) >= 0)
        {
            sql = string.Format(CRepZFJKSQL.REP21_01, _str1, _str, str2);
            DBHelp.ExeSql(idataAccess, sql);
        }
        else
        {
            sql = string.Format(CRepZFJKSQL.REP21_0, _str1, _str, str2);
            DBHelp.ExeSql(idataAccess, sql);
        }
        smethod13(idataAccess, _str, _str1, CHelp.ConvertDecimal(str2, 0, 0));
        sql = string.Format(CRepZFJKSQL.REP21_2, _str1, _str, str2);
        DBHelp.ExeSql(idataAccess, sql);
        DataTable dt = DBHelp.GetDt(string.Format(CRepZFJKSQL.SEARCH31, _str1, _str), "ZQJKZF2_SJZFJE");
        string str3 = "0";
        if (dt.Rows.Count > 0)
        {
            str3 = RMBCapitalization.smethod(CHelp.ConvertDecimal(dt.Rows[0]["SJZFJE"], 0, 0));
        }
        sql = string.Format(CRepZFJKSQL.REP21_3, _str1, _str, str3);
        DBHelp.ExeSql(idataAccess, sql);
        sql = string.Format(CRepZFJKSQL.REP22, _str1, _str);
        DBHelp.ExeSql(idataAccess, sql);
    }

    public static void smethod15(string _str, string _str1, string _str2, string _str3, [Optional, DefaultParameterValue(true)] bool _flag, [Optional, DefaultParameterValue(true)] bool _flag1)
    {
        IDataAccess idataAccess = DBHelp.IniIDA();
        idataAccess.OpenDatabase();
        if (!_flag || !DBHelp.GetDt(string.Format("select * from xmqc where bdid='{0}' and qcid='{1}'", _str, _str1), "dtTemp").Rows[0]["zt"].Equals(1))
        {
            try
            {
                idataAccess.BeginTrans();
                DataSet dataSet = new DataSet();
                smethod5(_str1, _str, _str2, _str3);
                smethod7(idataAccess, _str1, _str);
                smethod8(idataAccess, dataSet, _str1, _str);
                smethod9(idataAccess, dataSet, _str1, _str);
                //smethod10(idataAccess, dataSet, _str1, _str);
                smethod14(idataAccess, _str1, _str);
                if (dataSet.HasChanges())
                {
                    idataAccess.Update(dataSet, true);
                }
                smethod11(idataAccess, _str1, _str);
                idataAccess.Commit();
            }
            catch (Exception exception)
            {
                Log.Write("CreateRepData:" + exception.Message);
                idataAccess.RollBack();
            }
        }
    }

    public static void smethod2(IDataAccess idataAccess, DataRow dataRow, string _str, string _str1)
    {
        dataRow["qcms"] = "第" + _str + "期扣款";
        dataRow.EndEdit();
    }

    public static void smethod3(object sender, DataColumnChangeEventArgs e)
    {
        if (e.Row.Table.Columns.Contains("UPHVS") && !e.Column.ColumnName.Equals("UPHVS"))
        {
            e.Row["UPHVS"] = DateTime.Now.ToString() + "|" + Guid.NewGuid();
        }
    }

    public static void smethod4(IDataAccess idataAccess, DataSet dataSet, string _str, string _str1, [Optional, DefaultParameterValue(true)] bool _flag)
    {
        dataSet.Merge(idataAccess.ExecuteDataSet(_str, CommandType.Text, _str1));
        if (_flag)
        {
            dataSet.Tables[_str1].ColumnChanging += new DataColumnChangeEventHandler(Class39.smethod3);
            dataSet.Tables[_str1].TableNewRow += new DataTableNewRowEventHandler(Class28.smethod);
        }
    }

    //构造动员预付款和材料预付款
    public static void smethod5(string _str, string _str1, string _str2, string _str3)
    {
        DataRow row;
        IDataAccess idataAccess = DBHelp.IniIDA();
        DataSet ds = new DataSet();
        string sql = string.Format("select * from QTJL_DYYFK where bdid='{0}' and qcid='{1}'", _str1, _str);
        DBHelp.ExecuteDataSet(ds, sql, "QTJL_DYYFK");
        DataTable table = ds.Tables["QTJL_DYYFK"];
        if (table.Rows.Count == 0)
        {
            row = table.NewRow();
            row["id"] = Guid.NewGuid();
            row["xmid"] = _str2;
            row["yzid"] = _str3;
            row["bdid"] = _str1;
            row["qcid"] = _str;
            table.Rows.Add(row);
        }
        else
        {
            row = table.Rows[0];
        }
        row["qcid"] = _str;
        SetDYYFK(idataAccess, row, _str1, _str);
        Log.Write("SetDYYFK(idaClient, row) End");
        sql = string.Format("select * from QTJL_CLYFK  where bdid='{0}' and qcid='{1}'", _str1, _str);
        DBHelp.ExecuteDataSet(ds, sql, "QTJL_CLYFK");
        table = ds.Tables["QTJL_CLYFK"];
        if (table.Rows.Count == 0)
        {
            row = table.NewRow();
            row["id"] = Guid.NewGuid();
            row["xmid"] = _str2;
            row["yzid"] = _str3;
            row["bdid"] = _str1;
            row["qcid"] = _str;
            table.Rows.Add(row);
        }
        else
        {
            row = table.Rows[0];
        }
        row["qcid"] = _str;
        smethod1(idataAccess, row, _str, _str1);
        idataAccess.Update(ds, true);
    }

    public static void smethod6(IDataAccess idataAccess, string _str, string _str1)
    {
        string format = "select zjlx,sum(htje) as htje from jlqd where bdid='{0}' group by zjlx";
        format = string.Format(format, _str1);
        foreach (DataRow row in DBHelp.GetDt(idataAccess, format, "dtTemp").Rows)
        {
            format = string.Format("update REP_ZQZFZS set htje={3},bghje={3} where yjd=-1 and bdid='{0}' and qcid={1} and zjlx='{2}'", new object[] { _str1, _str, row["zjlx"].ToString(), row["htje"].ToString() });
            DBHelp.ExeSql(idataAccess, format);
        }
    }

    public static void smethod7(IDataAccess idataAccess, string _str, string _str1)
    {
        string sql = string.Format(CRepSQL.DEL_ZQZFZS, _str1, _str);
        DBHelp.ExeSql(idataAccess, sql);
        sql = CHelp.smethod(string.Format(CRepSQL.INSERT_ZQZFZS_QD, _str1, _str));
        DBHelp.ExeSql(idataAccess, sql);
        sql = CHelp.smethod(string.Format(CRepSQL.INSERT_ZQZFZS_QD1, _str1, _str));
        DBHelp.ExeSql(idataAccess, sql);
        sql = CHelp.smethod(string.Format(CRepSQL.INSERT_ZQZFZS_QD2, _str1, _str));
        DBHelp.ExeSql(idataAccess, sql);
        sql = string.Format(CRepSQL.UPDATE_ZQZFZS, _str1, _str);
        DBHelp.ExeSql(idataAccess, sql);
        sql = "update REP_ZQZFZS set zjlx=substring(qdbh,1,1) where bdid='{0}' and qcid={1}";
        sql = string.Format(sql, _str1, _str);
        DBHelp.ExeSql(idataAccess, sql);
        sql = string.Format(CRepSQL.DEL_GCBG, _str1, _str);
        DBHelp.ExeSql(idataAccess, sql);
        sql = CHelp.smethod(string.Format(CRepSQL.INSERT_GCBG_QD, _str1, _str));
        DBHelp.ExeSql(idataAccess, sql);
    }

    public static void smethod8(IDataAccess idataAccess, DataSet dataSet, string _str, string _str1)
    {
        string exeStr = "";
        exeStr = CHelp.smethod(string.Format(CRepSQL.ZQZFZS, _str1, _str));
        dataSet.Merge(idataAccess.ExecuteDataSet(exeStr, CommandType.Text, "REP_ZQZFZS"));
        DataTable table = dataSet.Tables["REP_ZQZFZS"];
        exeStr = CHelp.smethod(string.Format(CRepSQL.ZQZFZS_1, _str1, _str));
        DataTable table2 = DBHelp.GetDt(idataAccess, exeStr, "dtPZH");
        exeStr = string.Format(CRepSQL.ZQZFZS_2, _str1, _str);
        DataTable table3 = DBHelp.GetDt(idataAccess, exeStr, "dtZH");
        exeStr = CHelp.smethod(string.Format(CRepSQL.ZQZFZS_BZ, _str1, _str));
        DataTable table4 = DBHelp.GetDt(idataAccess, exeStr, "ZQZFZS_BZ");
        foreach (DataRow row in table.Rows)
        {
            DataRow row2;
            DataRow row3;
            table2.DefaultView.RowFilter = "qdbh='" + row["qdbh"].ToString() + "'";
            foreach (DataRowView view in table2.DefaultView)
            {
                row2 = view.Row;
                if (!row["pzbh"].ToString().Trim().Equals(""))
                {
                    (row3 = row)["pzbh"] = row3["pzbh"] + "/";
                }
                (row3 = row)["pzbh"] = row3["pzbh"] + row2["pzbh"].ToString();
            }
            table3.DefaultView.RowFilter = "qdbh='" + row["qdbh"].ToString() + "'";
            foreach (DataRowView view in table3.DefaultView)
            {
                row2 = view.Row;
                if (!row["zh"].ToString().Trim().Equals(""))
                {
                    (row3 = row)["zh"] = row3["zh"] + "/";
                }
                (row3 = row)["zh"] = row3["zh"] + row2["qqzh"].ToString();
            }
            string str2 = row["qdbh"].ToString();
            if ((str2.Length.Equals(3) || str2.Equals("D")) || str2.Equals("Z"))
            {
                if (str2.Equals("D") || str2.Equals("Z"))
                {
                    str2 = str2 + "00";
                }
                table4.DefaultView.RowFilter = "bz='" + str2 + "'";
                foreach (DataRowView view in table4.DefaultView)
                {
                    row2 = view.Row;
                    row["BQJLJE"] = row2["BQJLJE"];
                    row["SQMJLJE"] = row2["SQMJLJE"];
                    row["BQMJLJE"] = row2["BQMJLJE"];
                }
            }
        }
    }

    public static void smethod9(IDataAccess idataAccess, DataSet dataSet, string _str, string _str1)
    {
        string exeStr = "";
        exeStr = string.Format(CRepSQL.GCBG, _str1, _str);
        dataSet.Merge(idataAccess.ExecuteDataSet(exeStr, CommandType.Text, "REP_GCBG"));
        DataTable table = dataSet.Tables["REP_GCBG"];
        exeStr = string.Format(CRepSQL.GCBG_1, _str1, _str);
        DataTable table2 = DBHelp.GetDt(idataAccess, exeStr, "dtPZH");
        exeStr = string.Format(CRepSQL.GCBG_2, _str1, _str);
        DataTable table3 = DBHelp.GetDt(idataAccess, exeStr, "dtBGLH");
        foreach (DataRow row in table.Rows)
        {
            DataRow row2;
            DataRow row3;
            table2.DefaultView.RowFilter = "qdbh='" + row["qdbh"].ToString() + "'";
            foreach (DataRowView view in table2.DefaultView)
            {
                row2 = view.Row;
                if (!row["pzbh"].ToString().Trim().Equals(""))
                {
                    (row3 = row)["pzbh"] = row3["pzbh"] + "/";
                }
                (row3 = row)["pzbh"] = row3["pzbh"] + row2["pzbh"].ToString();
            }
            table3.DefaultView.RowFilter = "qdbh='" + row["qdbh"].ToString() + "'";
            foreach (DataRowView view in table3.DefaultView)
            {
                row2 = view.Row;
                if (!row["zh"].ToString().Trim().Equals(""))
                {
                    (row3 = row)["zh"] = row3["zh"] + "/";
                }
                (row3 = row)["zh"] = row3["zh"] + row2["bglh"].ToString();
            }
        }
    }
}

